package com.kob.backend.service.impl.auction;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kob.backend.mapper.DefaultTaskMapper;
import com.kob.backend.pojo.DefaultTask;
import com.kob.backend.service.auction.DefaultTaskService;
import com.kob.backend.service.impl.utils.CommonUtils;
import com.kob.backend.vo.DefaultTaskVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>{@code
 *
 * }</pre>
 *
 * @author Summerday
 * @date 2023/4/15
 */
@Service
public class DefaultTaskServiceImpl extends ServiceImpl<DefaultTaskMapper, DefaultTask> implements DefaultTaskService {

    @Override
    public List<DefaultTaskVo> getDefaultTaskList() {
        List<DefaultTask> list = list();
        List<DefaultTaskVo> ans = new ArrayList<>();
        for(DefaultTask dt : list) {
            DefaultTaskVo defaultTaskVo = DT2V(dt);
            ans.add(defaultTaskVo);
        }
        return ans;
    }

    private DefaultTaskVo DT2V(DefaultTask dt) {
        DefaultTaskVo v = new DefaultTaskVo();
        v.setDescription(dt.getDescription());
        v.setTaskName(dt.getTaskName());
        v.setId(dt.getId());
        v.setCreateTime(dt.getCreateTime());
        List<String> ps = CommonUtils.split(dt.getPropertyList());
        List<String> cs = CommonUtils.split(dt.getCostList());
        Map<String, Integer> costs = new HashMap<>();
        for(int i = 0; i < ps.size(); i ++) {
            costs.put(ps.get(i), Integer.parseInt(cs.get(i)));
        }
        v.setCosts(costs);
        return v;
    }

    @Override
    public DefaultTaskVo get(Integer id) {
        DefaultTask task = getOne(new QueryWrapper<DefaultTask>().eq("id", id));
        return DT2V(task);
    }
}
